from typing import Optional, Tuple

from django.db.models import QuerySet

from server.apps.todo.logic.jobs import commands, queries, validation
from server.apps.todo.models import ToDo


def edit(
    job_id: Optional[str],
    title: Optional[str],
    description: Optional[str],
    done: Optional[bool],
) -> Tuple[bool, QuerySet[ToDo]]:
    """Validates data, maybe edites the job."""
    validated_data = validation.validate(
        title=title,
        description=description,
        done=done,
    )
    if validated_data:
        commands.edit(job_id, validated_data)

    return validated_data is not None


def done(job_id):
    job = commands.done(job_id)

    return job is not None


def delete(job_id):
    job = commands.delete(job_id)

    return job is not None